package com.yyz.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yyz.lease.model.entity.SystemPost;
import com.yyz.lease.model.entity.SystemUser;
import com.yyz.lease.web.admin.mapper.SystemPostMapper;
import com.yyz.lease.web.admin.mapper.SystemUserMapper;
import com.yyz.lease.web.admin.service.SystemUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyz.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.yyz.lease.web.admin.vo.system.user.SystemUserQueryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 */
@Service
@RequiredArgsConstructor
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    private final SystemUserMapper systemUserMapper;
    private final SystemPostMapper systemPostMapper;

    /**
     * 分页查询员工信息表
     */
    @Override
    public IPage<SystemUserItemVo> pageSystemUserItemVo(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageSystemUserItemVo(page,queryVo);
    }

    /**
     * 根据id查询员工信息
     */
    @Override
    public SystemUserItemVo getSystemUserItemVoById(Long id) {
        //查询员工信息表
        SystemUser systemUser = getById(id);

        //查询岗位信息表
        SystemPost systemPost = systemPostMapper.selectById(systemUser.getPostId());

        //封装数据
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        BeanUtils.copyProperties(systemUser,systemUserItemVo);
        systemUserItemVo.setPostName(systemPost.getName());

        return systemUserItemVo;
    }

    @Override
    public SystemUser getByUsername(String username) {
        return systemUserMapper.getByUsername(username);
    }
}




